﻿using System;
namespace Producers.Kis.Xtee.Riik.Ee.Producer.Kis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="RegularClaim", Namespace="http://producers.kis.xtee.riik.ee/producer/kis", Target=typeof(RegularClaim))]
    public class RegularClaimSerializer : global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.ClaimSerializer {
        
        public RegularClaimSerializer(IRegularClaim clazz) : 
                base(clazz) {
        }
        
        protected new IRegularClaim clazz {
            get {
                return ((IRegularClaim)(base.clazz));
            }
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("StateFeeCourt");
            if (clazz.StateFeeCourt!=null) {
                global::Xtee.Core.SerializationMetadata metaStateFeeCourt = this.GetMetaData(clazz.StateFeeCourt);
                Writer.WriteTypeAttribute(metaStateFeeCourt.TypeQualifiedName.Namespace, metaStateFeeCourt.TypeQualifiedName.Name);
                metaStateFeeCourt.NewSerializer(clazz.StateFeeCourt).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : StateFeeCourt");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("PetitionerMatters");
            if (clazz.PetitionerMatters!=null) {
                global::Xtee.Core.SerializationMetadata metaPetitionerMatters = this.GetMetaData(clazz.PetitionerMatters);
                Writer.WriteTypeAttribute(metaPetitionerMatters.TypeQualifiedName.Namespace, metaPetitionerMatters.TypeQualifiedName.Name);
                metaPetitionerMatters.NewSerializer(clazz.PetitionerMatters).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : PetitionerMatters");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="StateFeeCourt") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RegularClaim>StateFeeCourt");
                }
                global::Xtee.Core.SerializationMetadata metaStateFeeCourt = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IStateFeeCourt>(Reader, "StateFeeCourt", "http://producers.kis.xtee.riik.ee/producer/kis");
                clazz.StateFeeCourt = metaStateFeeCourt.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IStateFeeCourt>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("StateFeeCourt");
                    metaStateFeeCourt.NewSerializer(clazz.StateFeeCourt).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RegularClaim>StateFeeCourt", Reader.LocalName);
            }
            if (Reader.LocalName=="PetitionerMatters") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RegularClaim>PetitionerMatters");
                }
                global::Xtee.Core.SerializationMetadata metaPetitionerMatters = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IPetitionerMatters>(Reader, "PetitionerMatters", "http://producers.kis.xtee.riik.ee/producer/kis");
                clazz.PetitionerMatters = metaPetitionerMatters.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IPetitionerMatters>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("PetitionerMatters");
                    metaPetitionerMatters.NewSerializer(clazz.PetitionerMatters).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RegularClaim>PetitionerMatters", Reader.LocalName);
            }
        }
    }
}
